Back to Main Menu

Applying Assessment Form Results

Sample Script

This example below outlines how to take a set of data and assign to an assessment form as an 'Assessment Form Result'. The 'Assessment Form Result' is then assigned to an assessment task. For a more general overview of the application of assessment form results, please refer to this article on the Integration section.

  1. """
  2. Example script to apply an assessment result to a task
  3. (Assetic.Assessments.py)
  4. 1. create (POST) a form result.
  5. 2. use the generated ID in form result response to link to the
  6. assessment task
  7. """
  8. import assetic
  9. from datetime import datetime
  10. from datetime import timedelta
  11. #Assetic SDK instance
  12. asseticsdk = assetic.AsseticSDK('c:/users/you/assetic.ini',None,'Error')
  13. #assessment form result API
  14. assessresultapi = assetic.AssessmentFormResultApi()
  15. ##need some identifiers. These may come from GET /api/v2/assessmenttask
  16. ##which is in the AssessmentTaskApi, use method assessment_task_get which
  17. ##returns all tasks assigned to the logged in user
  18. taskguid = '375f575c-2b6b-e611-9469-06edd62954d7'
  19. formguid = 'e3244b32-286b-e611-9469-06edd62954d7'
  20. resourceguid = '36bee8ab-4e39-4f1d-b713-4eefa521fcd8'
  21. #define the assessor resource (need both guid & name)
  22. resource = assetic.Assetic3IntegrationRepresentationsRsResourceRepresentation()
  23. resource.id = resourceguid
  24. resource.display_name = 'Kevin Wilton'
  25. ##build the data. Structure of this changes for each form
  26. ##use the form API to get structure
  27. data = {"CONTROL0766":"1",
  28. "CONTROL0770":True,
  29. "CONTROL0771":"Tea Tree",
  30. "CONTROL07712":"melaleuca alternifolia"}
  31. #build the object to create the result entry
  32. form_result = assetic.Assetic3IntegrationRepresentationsAsmtFormResultRepresentation()
  33. form_result.form_id = formguid
  34. form_result.form_result_comment='created via api'
  35. form_result.form_result_start_time = datetime.isoformat(datetime.now() +
  36. timedelta(days=-7))
  37. form_result.form_result_end_time = datetime.isoformat(datetime.now()
  38. + timedelta(days=-5))
  39. form_result.form_result_last_modified = datetime.isoformat(datetime.now())
  40. form_result.form_result_status = 1
  41. form_result.form_result_rs_resource_id_assessed_by=resource
  42. form_result.data = data
  43. ##execute the post
  44. try:
  45. response = assessresultapi.assessment_form_result_post(form_result)
  46. except assetic.rest.ApiException as e:
  47. ##Log exception and exit
  48. asseticsdk.logger.error("Status {0}, Reason: {1}".format(e.status,e.reason))
  49. exit();
  50. ##check for error messages
  51. if response.get('Errors') != None:
  52. print(response.get('Errors'))
  53. exit();
  54. ##get response ID
  55. id = response['Data'][0]['Id']
  56. print(id)
  57. ##now link form result with task. First create api instance
  58. taskapi = assetic.AssessmentTaskApi()
  59. try:
  60. linkresponse = taskapi.assessment_task_link_asmt_form_result(taskguid,id)
  61. except assetic.rest.ApiException as e:
  62. #Log exception and exit
  63. asseticsdk.logger.error("Status {0}, Reason: {1}".format(e.status,e.reason))
  64. exit();
  65. print (linkresponse) #expect 'True'